package icu.qx.diagram.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import icu.qx.diagram.domain.Sales;
import icu.qx.diagram.service.ISalesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/diagram/sales")
public class SalesController extends BaseController {
    private final ISalesService iSalesService;
    @Autowired
    public SalesController(ISalesService iSalesService){this.iSalesService=iSalesService;}
    @RequiresPermissions("diagram:sales:list")
    @GetMapping("/list")
    public TableDataInfo list(Sales sales)
    {
        startPage();
        List<Sales> list=iSalesService.selectSalesList(sales);
        for(Sales s:list){
            s.setCreatorName(SecurityUtils.getUsername());
        }
        return getDataTable(list);
    }
    /**
     * 导出出货统计
     */
    @RequiresPermissions("diagram:sales:export")
    @Log(title = "出货统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Sales sales) {
        List<Sales> list = iSalesService.selectSalesList(sales);
        ExcelUtil<Sales> util = new ExcelUtil<>(Sales.class);
        util.exportExcel(response, list, "出货统计数据");
    }
}
